<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Inter in Binary Files</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Inter in Binary Files' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">bytecode</a></li><li><a href="index.html#3">Chapter 3: Their Instructions</a></li><li><b>Inter in Binary Files</b></li></ul></div>
<p class="purpose">To read or write inter between memory and binary files.</p>

<ul class="toc"><li><a href="3-iibf.html#SP1">&#167;1. Compression and the shibboleth</a></li><li><a href="3-iibf.html#SP10">&#167;10. Reading and writing inter to binary</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Compression and the shibboleth.</b>(Not the name of a band.) A binary Inter file opens with an 20-byte uncompressed
header:
</p>

<ul class="items"><li>(a) The first four bytes store a big-endian 32-bit word. Its numerical value
is given by the <span class="extract"><span class="extract-syntax">INTER_SHIBBOLETH</span></span> constant, but in fact this is the same as
the ASCII encoding of the letters <span class="extract"><span class="extract-syntax">intr</span></span>.
</li><li>(b) The second four bytes are all 0. This enables us to distinguish a binary
Inter file from a random text file which just happens to begin with those letters.
</li><li>(c) Words 2, 3 and 4 are then the three numerical parts of the current Inter
specification's semantic version number. For example, if that were 5.2.4, then
these words would be 5, 2 and 4 respectively.
</li></ul>
<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">INTER_SHIBBOLETH</span><span class="plain-syntax"> ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="constant-syntax">0x696E7472</span><span class="plain-syntax">)</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::test_file</span><span class="plain-syntax">(</span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">verdict</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BinaryFiles::try_to_open_for_reading</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">INTER_SHIBBOLETH</span><span class="plain-syntax">)) </span><span class="identifier-syntax">verdict</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">)) </span><span class="identifier-syntax">verdict</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">verdict</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>And this is a version which returns either the semver of Inter used in the
file, or else a null semver if the file isn't binary Inter:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::test_file_version</span><span class="plain-syntax">(</span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BinaryFiles::try_to_open_for_reading</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">VersionNumbers::null</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">INTER_SHIBBOLETH</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">VersionNumbers::null</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v1</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v2</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v3</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">VersionNumbers::null</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax"> = </span><a href="1-tiv.html#SP4" class="function-link"><span class="function-syntax">InterVersion::from_three_words</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">v1</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">V</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Once past the header, the data is a flat series of 32-bit values, but many
of those are in practice low values: small integers, ASCII character codes and
the like. Given the Inform GUI apps need to store quite a lot of precompiled
binary Inter files, we can reduce the app's footprint &mdash; by what turns out to be
about 14 MB &mdash; if we compress those files. We do this by writing each word as
a series of 1 to 5 bytes.
</p>

<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>The following scheme is used on every word after the header:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">VALUE</span><span class="plain-syntax">               </span><span class="identifier-syntax">ONE</span><span class="plain-syntax"> </span><span class="identifier-syntax">TO</span><span class="plain-syntax"> </span><span class="identifier-syntax">FIVE</span><span class="plain-syntax"> </span><span class="identifier-syntax">BYTES</span>
<span class="plain-syntax">    </span><span class="constant-syntax">00000000</span><span class="plain-syntax">-0000007</span><span class="identifier-syntax">f</span><span class="plain-syntax">   </span><span class="constant-syntax">0x</span><span class="identifier-syntax">xxxxxx</span>
<span class="plain-syntax">    </span><span class="constant-syntax">00000080</span><span class="plain-syntax">-00003</span><span class="identifier-syntax">fff</span><span class="plain-syntax">   </span><span class="constant-syntax">10x</span><span class="identifier-syntax">xxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span>
<span class="plain-syntax">    </span><span class="constant-syntax">00004000</span><span class="plain-syntax">-001</span><span class="identifier-syntax">fffff</span><span class="plain-syntax">   </span><span class="constant-syntax">110x</span><span class="identifier-syntax">xxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span>
<span class="plain-syntax">    </span><span class="constant-syntax">00200000</span><span class="plain-syntax">-3</span><span class="identifier-syntax">fffffff</span><span class="plain-syntax">   </span><span class="constant-syntax">11111111</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span>
<span class="plain-syntax">    </span><span class="constant-syntax">40000000</span><span class="plain-syntax">-4000001</span><span class="identifier-syntax">e</span><span class="plain-syntax">   </span><span class="constant-syntax">111</span><span class="identifier-syntax">xxxxx</span>
<span class="plain-syntax">    </span><span class="constant-syntax">4000001</span><span class="identifier-syntax">f</span><span class="plain-syntax">-</span><span class="identifier-syntax">ffffffff</span><span class="plain-syntax">   </span><span class="constant-syntax">11111111</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span><span class="plain-syntax">    </span><span class="identifier-syntax">xxxxxxxx</span>
</pre>
<p class="commentary">This is a little like UTF-8, but because there is no need to synchronise from an
arbitrary mid-file position, we can be more economical with bits; and we then
also optimise for the range just above <span class="extract"><span class="extract-syntax">40000000</span></span> because this is <span class="extract"><span class="extract-syntax">SYMBOL_BASE_VAL</span></span>,
and means that references in Inter bytecode to symbols cluster there. See
<a href="2-st.html" class="internal">Symbols Tables</a>.
</p>

<p class="commentary">Measurement on the binary Inter form of BasicInformKit, compiled for the 32d
architecture, came out as follows in February 2022:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Words</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax"> </span><span class="identifier-syntax">byte</span><span class="plain-syntax">(</span><span class="identifier-syntax">s</span><span class="plain-syntax">): </span><span class="constant-syntax">923439</span>
<span class="identifier-syntax">Words</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax"> </span><span class="identifier-syntax">byte</span><span class="plain-syntax">(</span><span class="identifier-syntax">s</span><span class="plain-syntax">): </span><span class="constant-syntax">81056</span>
<span class="identifier-syntax">Words</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span><span class="plain-syntax"> </span><span class="identifier-syntax">byte</span><span class="plain-syntax">(</span><span class="identifier-syntax">s</span><span class="plain-syntax">): </span><span class="constant-syntax">21939</span>
<span class="identifier-syntax">Words</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="constant-syntax">5</span><span class="plain-syntax"> </span><span class="identifier-syntax">byte</span><span class="plain-syntax">(</span><span class="identifier-syntax">s</span><span class="plain-syntax">): </span><span class="constant-syntax">17269</span>
<span class="constant-syntax">1043703</span><span class="plain-syntax"> </span><span class="identifier-syntax">words</span><span class="plain-syntax">, </span><span class="constant-syntax">1237713</span><span class="plain-syntax"> </span><span class="identifier-syntax">bytes:</span><span class="plain-syntax"> </span><span class="identifier-syntax">compression</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">.296472</span>
</pre>
<p class="commentary">That is, the compressed file is about 0.295 times the size of what it would be
if no compression were used. Other kits similarly produced 0.294220, 0.286038,
and so on: the ratio was fairly consistent. More could certainly be done (even
these compressed files reduce further if run through gzip), but it would be a
trade-off for complexity. At some point enough is good enough.
</p>

<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Compressed data exists only in files: decompression happens as data is read
into memory, and compression happens as it is written to the file.
</p>

<p class="commentary">This is the decoder. It stores the 32-bit unsigned value read in <span class="extract"><span class="extract-syntax">result</span></span>,
and returns <span class="extract"><span class="extract-syntax">TRUE</span></span> if all went well; if a file system error, or end of file,
occurs, then it returns <span class="extract"><span class="extract-syntax">FALSE</span></span> and the contents of <span class="extract"><span class="extract-syntax">result</span></span> are undefined.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::read_word</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::read_word</span></span>:<br/><a href="3-iibf.html#SP6">&#167;6</a>, <a href="3-iibf.html#SP10_1_2">&#167;10.1.2</a>, <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>, <a href="3-iibf.html#SP10_1_4">&#167;10.1.4</a>, <a href="3-iibf.html#SP10_1_5">&#167;10.1.5</a>, <a href="3-iibf.html#SP10_1_5_1">&#167;10.1.5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> *</span><span class="identifier-syntax">result</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">), </span><span class="identifier-syntax">c2</span><span class="plain-syntax">, </span><span class="identifier-syntax">c3</span><span class="plain-syntax">, </span><span class="identifier-syntax">c4</span><span class="plain-syntax">, </span><span class="identifier-syntax">c5</span><span class="plain-syntax">; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c1</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0xE0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">:     </span><span class="comment-syntax"> opening byte 000xxxxx</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0x20</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 001xxxxx</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0x40</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 010xxxxx</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0x60</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 011xxxxx</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c1</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0x80</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 100xxxxx</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0xa0</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 101xxxxx</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0x3f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c1</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">8</span><span class="plain-syntax">) + (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c2</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0xc0</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 110xxxxx</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0x1f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">c3</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c3</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c1</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">16</span><span class="plain-syntax">) +</span>
<span class="plain-syntax">                (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c2</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">8</span><span class="plain-syntax">) + (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c3</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0xe0</span><span class="identifier-syntax">:</span><span class="plain-syntax">  </span><span class="comment-syntax"> opening byte 111xxxxx</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c1</span><span class="plain-syntax"> != </span><span class="constant-syntax">0xff</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = </span><span class="constant-syntax">0x40000000</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">c1</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0x1f</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c3</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c3</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c4</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c4</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">c5</span><span class="plain-syntax"> = </span><span class="identifier-syntax">getc</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">); </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">c5</span><span class="plain-syntax"> == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                *</span><span class="identifier-syntax">result</span><span class="plain-syntax"> = (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c2</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">24</span><span class="plain-syntax">) +</span>
<span class="plain-syntax">                            (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c3</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">16</span><span class="plain-syntax">) +</span>
<span class="plain-syntax">                            (((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c4</span><span class="plain-syntax">) &lt;&lt; </span><span class="constant-syntax">8</span><span class="plain-syntax">) + ((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c5</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>And this version always returns a word:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::read_next</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::read_next</span></span>:<br/><a href="3-iibf.html#SP9">&#167;9</a>, <a href="3-iibf.html#SP10_1_2">&#167;10.1.2</a>, <a href="3-iibf.html#SP10_1_3">&#167;10.1.3</a>, <a href="3-iibf.html#SP10_1_3_1">&#167;10.1.3.1</a>, <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>, <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>, <a href="3-iibf.html#SP10_1_3_2_2_1">&#167;10.1.3.2.2.1</a>, <a href="3-iibf.html#SP10_1_3_2_3">&#167;10.1.3.2.3</a>, <a href="3-iibf.html#SP10_1_4">&#167;10.1.4</a>, <a href="3-iibf.html#SP10_1_5_2">&#167;10.1.5.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">I</span><span class="string-syntax">"binary Inter file incomplete"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>And this is the encoder. (Define the symbol <span class="extract"><span class="extract-syntax">MEASURE_INTER_COMPRESSION</span></span> to
see measurements like those above.) We return <span class="extract"><span class="extract-syntax">FALSE</span></span> if some file system error
occurred, making it impossible to write the data.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">#</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[10] = { </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax"> };</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">endif</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::write_word</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::write_word</span></span>:<br/><a href="3-iibf.html#SP9">&#167;9</a>, <a href="3-iibf.html#SP10_2_2">&#167;10.2.2</a>, <a href="3-iibf.html#SP10_2_3">&#167;10.2.3</a>, <a href="3-iibf.html#SP10_2_3_1">&#167;10.2.3.1</a>, <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a>, <a href="3-iibf.html#SP10_2_3_2_2">&#167;10.2.3.2.2</a>, <a href="3-iibf.html#SP10_2_3_2_2_1">&#167;10.2.3.2.2.1</a>, <a href="3-iibf.html#SP10_2_3_2_3">&#167;10.2.3.2.3</a>, <a href="3-iibf.html#SP10_2_4">&#167;10.2.4</a>, <a href="3-iibf.html#SP11_1">&#167;11.1</a>, <a href="3-iibf.html#SP11_2">&#167;11.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0x80</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[1]++;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">val</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0x4000</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[2]++;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0x80</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">8</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c2</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0x200000</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[3]++;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0xc0</span><span class="plain-syntax"> + (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">16</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) ((</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">8</span><span class="plain-syntax">) &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c3</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c2</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c3</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">0x40000000</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0x4000001f</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[1]++;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">((</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="constant-syntax">0xe0</span><span class="plain-syntax"> + </span><span class="identifier-syntax">val</span><span class="plain-syntax"> - </span><span class="constant-syntax">0x40000000</span><span class="plain-syntax">), </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[5]++;</span>
<span class="plain-syntax">        #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0xff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) ((</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">24</span><span class="plain-syntax">) &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c3</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) ((</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">16</span><span class="plain-syntax">) &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c4</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) ((</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">8</span><span class="plain-syntax">) &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c5</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">val</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0xFF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c2</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c3</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c4</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">putc</span><span class="plain-syntax">(</span><span class="identifier-syntax">c5</span><span class="plain-syntax">, </span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">) == </span><span class="identifier-syntax">EOF</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::write_compression_statistics</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::write_compression_statistics</span></span>:<br/><a href="3-iibf.html#SP10">&#167;10</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifdef</span><span class="plain-syntax"> </span><span class="identifier-syntax">MEASURE_INTER_COMPRESSION</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">tot_words</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">tot_bytes</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=1; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;10; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"Words in %d byte(s): %d\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">tot_words</span><span class="plain-syntax"> += </span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">tot_bytes</span><span class="plain-syntax"> += </span><span class="identifier-syntax">i</span><span class="plain-syntax">*</span><span class="identifier-syntax">Inter_words_with_byte_count</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"%d words, %d bytes: compression %g\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">tot_words</span><span class="plain-syntax">, </span><span class="identifier-syntax">tot_bytes</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        ((</span><span class="reserved-syntax">double</span><span class="plain-syntax">) </span><span class="identifier-syntax">tot_bytes</span><span class="plain-syntax">)/((</span><span class="reserved-syntax">double</span><span class="plain-syntax">) (4*</span><span class="identifier-syntax">tot_words</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Conventionally, texts are stored as a sequence of words:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">0</span><span class="plain-syntax">   </span><span class="identifier-syntax">length</span><span class="plain-syntax"> </span><span class="identifier-syntax">word</span><span class="plain-syntax"> </span><span class="identifier-syntax">L</span><span class="plain-syntax"> (= </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">empty</span><span class="plain-syntax"> </span><span class="identifier-syntax">text</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="constant-syntax">1</span><span class="plain-syntax">   </span><span class="identifier-syntax">first</span><span class="plain-syntax"> </span><span class="identifier-syntax">character</span>
<span class="plain-syntax">    ...</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">L</span><span class="plain-syntax">   </span><span class="identifier-syntax">last</span><span class="plain-syntax"> </span><span class="identifier-syntax">character</span>
</pre>
<p class="commentary">So, note, this is not a C-style null terminated string.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::read_text</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::read_text</span></span>:<br/><a href="3-iibf.html#SP10_1_2">&#167;10.1.2</a>, <a href="3-iibf.html#SP10_1_3_2_1">&#167;10.1.3.2.1</a>, <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>, <a href="3-iibf.html#SP10_1_3_2_3">&#167;10.1.3.2.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">L</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">PUT_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, (</span><span class="identifier-syntax">inchar32_t</span><span class="plain-syntax">) </span><span class="identifier-syntax">c</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::write_text</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::write_text</span></span>:<br/><a href="3-iibf.html#SP10_2_2">&#167;10.2.2</a>, <a href="3-iibf.html#SP10_2_3_2_1">&#167;10.2.3.2.1</a>, <a href="3-iibf.html#SP10_2_3_2_2">&#167;10.2.3.2.2</a>, <a href="3-iibf.html#SP10_2_3_2_3">&#167;10.2.3.2.3</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">binary_file</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">Str::get</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Reading and writing inter to binary.</b>So much for the encoding: now for the content, that is, what those words of
data actually are. The following functions to read and write binary Inter
files are presented in an interleaved way, showing each reader alongside its
corresponding writer.
</p>

<p class="commentary">Still, let's do the file-handling first:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::read</span><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_FILE_READ</span><span class="plain-syntax">, </span><span class="string-syntax">"(Reading binary inter file %f)\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">long</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">max_offset</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BinaryFiles::size</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BinaryFiles::open_for_reading</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> </span><span class="identifier-syntax">eloc</span><span class="plain-syntax"> = </span><a href="3-ie.html#SP2" class="function-link"><span class="function-syntax">InterErrors::interb_location</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_bookmark</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = </span><a href="2-bkm.html#SP4" class="function-link"><span class="function-syntax">InterBookmark::at_start_of_this_repository</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> = </span><a href="2-it.html#SP3" class="function-link"><span class="function-syntax">InterTree::warehouse</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *</span><span class="identifier-syntax">grid</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP18" class="function-link"><span class="function-syntax">InterInstruction::suspend_cross_referencing</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1" class="named-paragraph-link"><span class="named-paragraph">Read the content</span><span class="named-paragraph-number">10.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">Memory::I7_array_free</span><span class="plain-syntax">(</span><span class="identifier-syntax">grid</span><span class="plain-syntax">, </span><span class="constant-syntax">INTER_BYTECODE_MREASON</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Primitives::index_primitives_in_tree</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP18" class="function-link"><span class="function-syntax">InterInstruction::resume_cross_referencing</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-ic.html#SP7" class="function-link"><span class="function-syntax">InterInstruction::tree_lint</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::write</span><span class="plain-syntax">(</span><span class="identifier-syntax">filename</span><span class="plain-syntax"> *</span><span class="identifier-syntax">F</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_FILE_READ</span><span class="plain-syntax">, </span><span class="string-syntax">"(Writing binary inter file %f)\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">BinaryFiles::open_for_writing</span><span class="plain-syntax">(</span><span class="identifier-syntax">F</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_warehouse</span><span class="plain-syntax"> *</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> = </span><a href="2-it.html#SP3" class="function-link"><span class="function-syntax">InterTree::warehouse</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2" class="named-paragraph-link"><span class="named-paragraph">Write the content</span><span class="named-paragraph-number">10.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP8" class="function-link"><span class="function-syntax">BinaryInter::write_compression_statistics</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">STDOUT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10_1" class="paragraph-anchor"></a><b>&#167;10.1. </b>The file is organised in five blocks:
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the content</span><span class="named-paragraph-number">10.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_1" class="named-paragraph-link"><span class="named-paragraph">Read the header</span><span class="named-paragraph-number">10.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_2" class="named-paragraph-link"><span class="named-paragraph">Read the annotations</span><span class="named-paragraph-number">10.1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3" class="named-paragraph-link"><span class="named-paragraph">Read the resources</span><span class="named-paragraph-number">10.1.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_4" class="named-paragraph-link"><span class="named-paragraph">Read the symbol wirings</span><span class="named-paragraph-number">10.1.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_5" class="named-paragraph-link"><span class="named-paragraph">Read the bytecode</span><span class="named-paragraph-number">10.1.5</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10">&#167;10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2" class="paragraph-anchor"></a><b>&#167;10.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the content</span><span class="named-paragraph-number">10.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_1" class="named-paragraph-link"><span class="named-paragraph">Write the header</span><span class="named-paragraph-number">10.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_2" class="named-paragraph-link"><span class="named-paragraph">Write the annotations</span><span class="named-paragraph-number">10.2.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3" class="named-paragraph-link"><span class="named-paragraph">Write the resources</span><span class="named-paragraph-number">10.2.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_4" class="named-paragraph-link"><span class="named-paragraph">Write the symbol wirings</span><span class="named-paragraph-number">10.2.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_5" class="named-paragraph-link"><span class="named-paragraph">Write the bytecode</span><span class="named-paragraph-number">10.2.5</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10">&#167;10</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_1" class="paragraph-anchor"></a><b>&#167;10.1.1. </b>The header is uncompressed, so we call <span class="extract"><span class="extract-syntax">BinaryFiles::read_int32</span></span> and
<span class="extract"><span class="extract-syntax">BinaryFiles::write_int32</span></span> from <a href="../foundation/index.html" class="internal">foundation</a>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the header</span><span class="named-paragraph-number">10.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">INTER_SHIBBOLETH</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        ((</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"not a binary inter file"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v1</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v2</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) ||</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">BinaryFiles::read_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v3</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"header breaks off"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">BinaryFiles::close</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">file_version</span><span class="plain-syntax"> = </span><a href="1-tiv.html#SP4" class="function-link"><span class="function-syntax">InterVersion::from_three_words</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">v1</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="1-tiv.html#SP3" class="function-link"><span class="function-syntax">InterVersion::check_readable</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">file_version</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">semantic_version_number</span><span class="plain-syntax"> </span><span class="identifier-syntax">current_version</span><span class="plain-syntax"> = </span><a href="1-tiv.html#SP3" class="function-link"><span class="function-syntax">InterVersion::current</span></a><span class="plain-syntax">();</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">erm</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">erm</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"file '%f' holds Inter written for specification v%v, but I expect v%v"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">F</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">file_version</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">current_version</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">erm</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">erm</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1">&#167;10.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_1" class="paragraph-anchor"></a><b>&#167;10.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the header</span><span class="named-paragraph-number">10.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::write_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="constant-syntax">INTER_SHIBBOLETH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::write_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="1-tiv.html#SP4" class="function-link"><span class="function-syntax">InterVersion::to_three_words</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">v1</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v2</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">v3</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::write_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">v1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::write_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">v2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">BinaryFiles::write_int32</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">v3</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2">&#167;10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_2" class="paragraph-anchor"></a><b>&#167;10.1.2. </b>Next we have to describe the possible range of <a href="2-ann.html" class="internal">Annotations</a>. We need these
now, because they will be referred to in the symbol definitions in the
resource block later on.
</p>

<p class="commentary">This block is a sequence of records like so:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">Word</span><span class="plain-syntax">    </span><span class="identifier-syntax">Annotation</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Text</span><span class="plain-syntax">    </span><span class="identifier-syntax">Name</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Word</span><span class="plain-syntax">    </span><span class="identifier-syntax">Annotation</span><span class="plain-syntax"> </span><span class="identifier-syntax">type</span><span class="plain-syntax"> (</span><span class="identifier-syntax">a</span><span class="plain-syntax"> |*</span><span class="identifier-syntax">_IATYPE</span><span class="plain-syntax">| </span><span class="identifier-syntax">value</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary">terminated by the sentinel word <span class="extract"><span class="extract-syntax">INVALID_IANN</span></span>. There cannot be two blocks with
the same annotation ID; the order of blocks is not meaningful. In particular,
they are not necessarily in increasing order of ID.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the annotations</span><span class="named-paragraph-number">10.1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> = </span><span class="constant-syntax">INVALID_IANN</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">ID</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">INVALID_IANN</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">keyword</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::read_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">keyword</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">iatype</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-ann.html#SP2" class="function-link"><span class="function-syntax">SymbolAnnotation::declare</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">keyword</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">iatype</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="string-syntax">"conflicting annotation name '%S'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">keyword</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">err</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">keyword</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1">&#167;10.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_2" class="paragraph-anchor"></a><b>&#167;10.2.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the annotations</span><span class="named-paragraph-number">10.2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_annotation_form</span><span class="plain-syntax"> *</span><span class="identifier-syntax">IAF</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER</span><span class="plain-syntax">(</span><span class="identifier-syntax">IAF</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_annotation_form</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">IAF</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_ID</span><span class="plain-syntax"> != </span><span class="constant-syntax">INVALID_IANN</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">IAF</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::write_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">IAF</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotation_keyword</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">IAF</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iatype</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="constant-syntax">INVALID_IANN</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2">&#167;10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3" class="paragraph-anchor"></a><b>&#167;10.1.3. </b>There follows a block of resources. This consists of a single word giving
the count of the number of resources (which may be 0); then a table of warehouse
IDs; then a table of metadata for the resources.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the resources</span><span class="named-paragraph-number">10.1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_1" class="named-paragraph-link"><span class="named-paragraph">Read the table of warehouse ID numbers</span><span class="named-paragraph-number">10.1.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2" class="named-paragraph-link"><span class="named-paragraph">Read the table of resources proper</span><span class="named-paragraph-number">10.1.3.2</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1">&#167;10.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3" class="paragraph-anchor"></a><b>&#167;10.2.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the resources</span><span class="named-paragraph-number">10.2.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">) </span><span class="identifier-syntax">count</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">count</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_1" class="named-paragraph-link"><span class="named-paragraph">Write the table of warehouse ID numbers</span><span class="named-paragraph-number">10.2.3.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2" class="named-paragraph-link"><span class="named-paragraph">Write the table of resources proper</span><span class="named-paragraph-number">10.2.3.2</span></a></span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2">&#167;10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_1" class="paragraph-anchor"></a><b>&#167;10.1.3.1. </b>A problem we must deal with is that the bytecode for the original tree will
have been full of references to texts, and such, by means of their warehouse ID
numbers. As we read in this data, we can and will mimic the texts that those
numbers were referring to: but we cannot expect them to have the same IDs in
our warehouse that they had in the original.
</p>

<p class="commentary">For example, suppose a tree contained the text <span class="extract"><span class="extract-syntax">"passacaglia"</span></span> at warehouse ID 34;
that this tree was then saved out as a binary Inter file; and that we are now
reading that binary file in. We can certainly make a text reading <span class="extract"><span class="extract-syntax">"passacaglia"</span></span>,
but there is no reason to expect (and no way to oblige) it to have warehouse ID 34
in our tree <span class="extract"><span class="extract-syntax">I</span></span>.
</p>

<p class="commentary">Because of that we will need to keep careful track of how IDs in the binary file
compare to those in our tree in memory. This is the purpose of the <span class="extract"><span class="extract-syntax">grid</span></span> array.
So, for example, <span class="extract"><span class="extract-syntax">grid[34]</span></span> is the ID for the string where our copy of
<span class="extract"><span class="extract-syntax">"passacaglia"</span></span> goes.
</p>

<p class="commentary">The grid is read in from a table whose first word is the maximum warehouse ID
ever used in the original file, plus 1; and then is a list of words giving
the warehouse IDs for the resources in turn.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the table of warehouse ID numbers</span><span class="named-paragraph-number">10.1.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">grid</span><span class="plain-syntax"> = (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">((</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax">),</span>
<span class="plain-syntax">            </span><span class="constant-syntax">INTER_BYTECODE_MREASON</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">: </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-it.html#SP3" class="function-link"><span class="function-syntax">InterTree::global_scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-it.html#SP3" class="function-link"><span class="function-syntax">InterTree::root_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP4" class="function-link"><span class="function-syntax">InterWarehouse::create_resource</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">-1;</span>
<span class="plain-syntax">                </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"max incorrect"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">original_ID</span><span class="plain-syntax">] = </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3">&#167;10.1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_1" class="paragraph-anchor"></a><b>&#167;10.2.3.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the table of warehouse ID numbers</span><span class="named-paragraph-number">10.2.3.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">max</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">n</span><span class="plain-syntax">+1 &gt; </span><span class="identifier-syntax">max</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">max</span><span class="plain-syntax"> = </span><span class="identifier-syntax">n</span><span class="plain-syntax">+1;</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">max</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">n</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">n</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3">&#167;10.2.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2" class="paragraph-anchor"></a><b>&#167;10.1.3.2. </b>The table of resources is then a series of records, one for each resource.
Each record begins with a type word, which must be one of the <span class="extract"><span class="extract-syntax">*_IRSRC</span></span> values.
After that, the content (and record length) depends on the type.
</p>

<p class="commentary">The first two resources in this table are always:
</p>

<ul class="items"><li>(i) the symbols table for the root package, which holds global symbols such
as primitive names; and
</li><li>(ii) the root package itself.
</li></ul>
<p class="commentary">The sequence is otherwise not meaningful. It should not be assumed that
resources will be in increasing warehouse ID order.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the table of resources proper</span><span class="named-paragraph-number">10.1.3.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">count</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"warehouse ID out of range"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">original_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax"> - </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">original_ID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">X</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TEXT_IRSRC:</span><span class="plain-syntax">          </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2_1" class="named-paragraph-link"><span class="named-paragraph">Read a string resource</span><span class="named-paragraph-number">10.1.3.2.1</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">SYMBOLS_TABLE_IRSRC:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2_2" class="named-paragraph-link"><span class="named-paragraph">Read a symbols table resource</span><span class="named-paragraph-number">10.1.3.2.2</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NODE_LIST_IRSRC:</span><span class="plain-syntax">     </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2_4" class="named-paragraph-link"><span class="named-paragraph">Read a node list resource</span><span class="named-paragraph-number">10.1.3.2.4</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PACKAGE_REF_IRSRC:</span><span class="plain-syntax">   </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2_3" class="named-paragraph-link"><span class="named-paragraph">Read a package resource</span><span class="named-paragraph-number">10.1.3.2.3</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"unknown resource type"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3">&#167;10.1.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2" class="paragraph-anchor"></a><b>&#167;10.2.3.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the table of resources proper</span><span class="named-paragraph-number">10.2.3.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">RT</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP6" class="function-link"><span class="function-syntax">InterWarehouse::resource_type_code</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">RT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">RT</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TEXT_IRSRC:</span><span class="plain-syntax">          </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2_1" class="named-paragraph-link"><span class="named-paragraph">Write a string resource</span><span class="named-paragraph-number">10.2.3.2.1</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">SYMBOLS_TABLE_IRSRC:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2_2" class="named-paragraph-link"><span class="named-paragraph">Write a symbols table resource</span><span class="named-paragraph-number">10.2.3.2.2</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">PACKAGE_REF_IRSRC:</span><span class="plain-syntax">   </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2_3" class="named-paragraph-link"><span class="named-paragraph">Write a package resource</span><span class="named-paragraph-number">10.2.3.2.3</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">NODE_LIST_IRSRC:</span><span class="plain-syntax">     </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2_4" class="named-paragraph-link"><span class="named-paragraph">Write a node list resource</span><span class="named-paragraph-number">10.2.3.2.4</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">default:</span><span class="plain-syntax"> </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"unimplemented resource type"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3">&#167;10.2.3</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2_1" class="paragraph-anchor"></a><b>&#167;10.1.3.2.1. </b>A text resource is <span class="extract"><span class="extract-syntax">TEXT_IRSRC</span></span> followed by a single text, giving its content.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read a string resource</span><span class="named-paragraph-number">10.1.3.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">txt</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">STORE_POINTER_text_stream</span><span class="plain-syntax">(</span><span class="identifier-syntax">txt</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::read_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">txt</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2_1" class="paragraph-anchor"></a><b>&#167;10.2.3.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write a string resource</span><span class="named-paragraph-number">10.2.3.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">txt</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP7" class="function-link"><span class="function-syntax">InterWarehouse::get_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::write_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">txt</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2_2" class="paragraph-anchor"></a><b>&#167;10.1.3.2.2. </b>A symbols table resource is <span class="extract"><span class="extract-syntax">SYMBOLS_TABLE_IRSRC</span></span> followed by a list of records,
one for each symbol:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">within</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbols</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> (</span><span class="identifier-syntax">always</span><span class="plain-syntax"> </span><span class="constant-syntax">SYMBOL_BASE_VAL</span><span class="plain-syntax"> </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">greater</span><span class="plain-syntax">, </span><span class="identifier-syntax">so</span><span class="plain-syntax"> </span><span class="identifier-syntax">nonzero</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">symbol</span><span class="plain-syntax"> </span><span class="identifier-syntax">type</span><span class="plain-syntax"> (</span><span class="identifier-syntax">one</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> |*</span><span class="identifier-syntax">_ISYMT</span><span class="plain-syntax">| </span><span class="identifier-syntax">values</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">persistent</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text</span><span class="plain-syntax">    </span><span class="identifier-syntax">identifier</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbol</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table</span><span class="plain-syntax">   </span><span class="identifier-syntax">annotations</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> (</span><span class="identifier-syntax">see</span><span class="plain-syntax"> </span><span class="identifier-syntax">below</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text</span><span class="plain-syntax">    </span><span class="identifier-syntax">text</span><span class="plain-syntax"> </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbol</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">wired</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> (</span><span class="reserved-syntax">if</span><span class="plain-syntax"> </span><span class="identifier-syntax">it</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">a</span><span class="plain-syntax"> </span><span class="identifier-syntax">plug:</span><span class="plain-syntax"> </span><span class="identifier-syntax">otherwise</span><span class="plain-syntax">, </span><span class="identifier-syntax">omitted</span><span class="plain-syntax">)</span>
</pre>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read a symbols table resource</span><span class="named-paragraph-number">10.1.3.2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tab</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tab</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> = </span><a href="2-st.html#SP2" class="function-link"><span class="function-syntax">InterSymbolsTable::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">STORE_POINTER_inter_symbols_table</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbol_ID</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">symbol_ID</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">symbol_ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">identifier</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">st</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::read_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">identifier</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><a href="2-st.html#SP10" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_name_creating_at_ID</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">identifier</span><span class="plain-syntax">, </span><span class="identifier-syntax">symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-sym.html#SP5" class="function-link"><span class="function-syntax">InterSymbol::set_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">st</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-sym.html#SP7" class="function-link"><span class="function-syntax">InterSymbol::set_persistent_flags</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">flags</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_3_2_2_1" class="named-paragraph-link"><span class="named-paragraph">Read the annotations for a symbol</span><span class="named-paragraph-number">10.1.3.2.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::read_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-tw2.html#SP7" class="function-link"><span class="function-syntax">Wiring::wire_to_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_BINARY</span><span class="plain-syntax">, </span><span class="string-syntax">"Read symbol $3\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">identifier</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2_2" class="paragraph-anchor"></a><b>&#167;10.2.3.2.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write a symbols table resource</span><span class="named-paragraph-number">10.2.3.2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_SYMBOLS_TABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><a href="2-sym.html#SP5" class="function-link"><span class="function-syntax">InterSymbol::get_type</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><a href="2-sym.html#SP7" class="function-link"><span class="function-syntax">InterSymbol::get_persistent_flags</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::write_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><a href="2-sym.html#SP19" class="function-link"><span class="function-syntax">InterSymbol::identifier</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_2_3_2_2_1" class="named-paragraph-link"><span class="named-paragraph">Write the annotations for a symbol</span><span class="named-paragraph-number">10.2.3.2.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-sym.html#SP13" class="function-link"><span class="function-syntax">InterSymbol::is_plug</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">N</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP7" class="function-link"><span class="function-syntax">Wiring::wired_to_name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::write_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2_2_1" class="paragraph-anchor"></a><b>&#167;10.1.3.2.2.1. </b>The annotations table for a single symbol begins with a word in the form
<span class="extract"><span class="extract-syntax">(bm &lt;&lt; 6) + n</span></span>, where <span class="extract"><span class="extract-syntax">bm</span></span> is the bitmap of its boolean annotations, and <span class="extract"><span class="extract-syntax">n</span></span>
is the number of non-boolean ones it has &mdash; which might be 0.
</p>

<p class="commentary">This word is then followed by <span class="extract"><span class="extract-syntax">n</span></span> pairs:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">non</span><span class="plain-syntax">-</span><span class="identifier-syntax">boolean</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">non</span><span class="plain-syntax">-</span><span class="identifier-syntax">boolean</span><span class="plain-syntax"> </span><span class="identifier-syntax">annotation</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span>
</pre>
<p class="commentary">The meaning of the value depends on the annotation type.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the annotations for a symbol</span><span class="named-paragraph-number">10.1.3.2.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">bm</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">.</span><span class="element-syntax">boolean_annotations</span><span class="plain-syntax"> |= (</span><span class="identifier-syntax">bm</span><span class="plain-syntax"> / </span><span class="constant-syntax">0x20</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">L</span><span class="plain-syntax"> = </span><span class="identifier-syntax">bm</span><span class="plain-syntax"> &amp; </span><span class="constant-syntax">0x1f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">L</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_annotation</span><span class="plain-syntax"> </span><span class="identifier-syntax">IA</span><span class="plain-syntax"> = </span><a href="2-ann.html#SP9" class="function-link"><span class="function-syntax">SymbolAnnotation::from_pair</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, </span><span class="identifier-syntax">c2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-ann.html#SP8" class="function-link"><span class="function-syntax">SymbolAnnotation::is_invalid</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">IA</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"invalid annotation"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">IA</span><span class="plain-syntax">.</span><span class="element-syntax">annot</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">iatype</span><span class="plain-syntax"> == </span><span class="constant-syntax">TEXTUAL_IATYPE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IA</span><span class="plain-syntax">.</span><span class="element-syntax">annot_value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">IA</span><span class="plain-syntax">.</span><span class="element-syntax">annot_value</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><a href="2-ann.html#SP6" class="function-link"><span class="function-syntax">SymbolAnnotation::set</span></a><span class="plain-syntax">(-1, </span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">IA</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3_2_2">&#167;10.1.3.2.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2_2_1" class="paragraph-anchor"></a><b>&#167;10.2.3.2.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the annotations for a symbol</span><span class="named-paragraph-number">10.2.3.2.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_annotation_set</span><span class="plain-syntax"> *</span><span class="identifier-syntax">set</span><span class="plain-syntax"> = &amp;(</span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">annotations</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">0x20</span><span class="plain-syntax">*((</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">set</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">boolean_annotations</span><span class="plain-syntax">) +</span>
<span class="plain-syntax">        (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">LinkedLists::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">set</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">other_annotations</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">set</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">other_annotations</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_annotation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">A</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">A</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_annotation</span><span class="plain-syntax">, </span><span class="identifier-syntax">set</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">other_annotations</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="constant-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">c1</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">c2</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><a href="2-ann.html#SP9" class="function-link"><span class="function-syntax">SymbolAnnotation::to_pair</span></a><span class="plain-syntax">(*</span><span class="identifier-syntax">A</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">c1</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">c2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">c2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3_2_2">&#167;10.2.3.2.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2_3" class="paragraph-anchor"></a><b>&#167;10.1.3.2.3. </b>A package resource is <span class="extract"><span class="extract-syntax">PACKAGE_REF_IRSRC</span></span> followed by:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">parent</span><span class="plain-syntax"> </span><span class="identifier-syntax">package</span><span class="plain-syntax">, </span><span class="identifier-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="reserved-syntax">for</span><span class="plain-syntax"> </span><span class="identifier-syntax">the</span><span class="plain-syntax"> </span><span class="identifier-syntax">root</span><span class="plain-syntax"> </span><span class="identifier-syntax">package</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">persistent</span><span class="plain-syntax"> </span><span class="identifier-syntax">package</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbols</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text</span><span class="plain-syntax">    </span><span class="identifier-syntax">package</span><span class="plain-syntax"> </span><span class="identifier-syntax">name</span>
</pre>
<p class="commentary">The name isn't used much here, and it's arguably wasteful to store it: the
alternative would be to use some further flags marking the identity of certain
special packages (such as <span class="extract"><span class="extract-syntax">connectors</span></span>). But having the names of packages be
easy to determine from the binary Inter file seems no bad thing, and it doesn't
consume so very many extra bytes. Package names are short and compress well.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read a package resource</span><span class="named-paragraph-number">10.1.3.2.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">parent_package_resource_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbols_table_resource_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">parent</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">parent_package_resource_ID</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">parent_package_resource_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">parent_package_resource_ID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">parent</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP9" class="function-link"><span class="function-syntax">InterWarehouse::get_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">parent_package_resource_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">stored_package</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP9" class="function-link"><span class="function-syntax">InterWarehouse::get_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">stored_package</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">stored_package</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP3" class="function-link"><span class="function-syntax">InterPackage::new</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">STORE_POINTER_inter_package</span><span class="plain-syntax">(</span><span class="identifier-syntax">stored_package</span><span class="plain-syntax">), </span><span class="identifier-syntax">stored_package</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="2-pck.html#SP14" class="function-link"><span class="function-syntax">InterPackage::set_persistent_flags</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">stored_package</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">flags</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">symbols_table_resource_ID</span><span class="plain-syntax"> != </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">symbols_table_resource_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">symbols_table_resource_ID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><a href="2-pck.html#SP9" class="function-link"><span class="function-syntax">InterPackage::set_scope</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">stored_package</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">symbols_table_resource_ID</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::read_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LargeScale::note_package_name</span><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">stored_package</span><span class="plain-syntax">, </span><span class="identifier-syntax">N</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">N</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2_3" class="paragraph-anchor"></a><b>&#167;10.2.3.2.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write a package resource</span><span class="named-paragraph-number">10.2.3.2.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP9" class="function-link"><span class="function-syntax">InterWarehouse::get_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">P</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no package for warehouse ID"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">par</span><span class="plain-syntax"> = </span><a href="2-pck.html#SP5" class="function-link"><span class="function-syntax">InterPackage::parent</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">par</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">par</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><a href="2-pck.html#SP14" class="function-link"><span class="function-syntax">InterPackage::get_persistent_flags</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">package_scope</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP9" class="function-link"><span class="function-syntax">BinaryInter::write_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><a href="2-pck.html#SP7" class="function-link"><span class="function-syntax">InterPackage::name</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">));</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_3_2_4" class="paragraph-anchor"></a><b>&#167;10.1.3.2.4. </b>A node list resource consists only of the word <span class="extract"><span class="extract-syntax">NODE_LIST_IRSRC</span></span>, with no
further data. That's because node lists are built fresh as instructions are
read in. So on writing we need do nothing, and on reading, we only need to
create the empty node list.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read a node list resource</span><span class="named-paragraph-number">10.1.3.2.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw.html#SP10" class="function-link"><span class="function-syntax">InterWarehouse::get_node_list</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><a href="2-tw.html#SP11" class="function-link"><span class="function-syntax">InterWarehouse::create_ref_at</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">STORE_POINTER_inter_node_list</span><span class="plain-syntax">(</span><a href="2-inl.html#SP1" class="function-link"><span class="function-syntax">InterNodeList::new</span></a><span class="plain-syntax">()), </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_3_2_4" class="paragraph-anchor"></a><b>&#167;10.2.3.2.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write a node list resource</span><span class="named-paragraph-number">10.2.3.2.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    ;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2_3_2">&#167;10.2.3.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_4" class="paragraph-anchor"></a><b>&#167;10.1.4. </b>Now for the symbol wiring block. This has to be here, after all the symbols
tables and packages have been made, so that cross-references can be sorted out.
The block records all pairs <span class="extract"><span class="extract-syntax">S1</span></span> and <span class="extract"><span class="extract-syntax">S2</span></span> such that <span class="extract"><span class="extract-syntax">S1 ~~&gt; S2</span></span>; note that it
does not record wirings to names, only wirings to symbols.
</p>

<p class="commentary">Rather than storing these pairs in no order, we group them by the origin table,
that is, by the symbols table holding <span class="extract"><span class="extract-syntax">S1</span></span>. So the block consists of one record
for each table which needs to make some wirings:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbols</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">holding</span><span class="plain-syntax"> </span><span class="identifier-syntax">S1</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">table</span><span class="plain-syntax">   </span><span class="identifier-syntax">wirings</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span>
</pre>
<p class="commentary">This is terminated by a 0 word, which is safe since 0 is never a valid warehouse
ID: see <a href="2-tw.html" class="internal">The Warehouse</a>. The sub-table of wirings is then a sequence of these:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">        </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">symbol</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">this</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">S1</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">warehouse</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">symbols</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">holding</span><span class="plain-syntax"> </span><span class="identifier-syntax">S2</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">word</span><span class="plain-syntax">    </span><span class="identifier-syntax">symbol</span><span class="plain-syntax"> </span><span class="identifier-syntax">ID</span><span class="plain-syntax"> </span><span class="identifier-syntax">in</span><span class="plain-syntax"> </span><span class="identifier-syntax">that</span><span class="plain-syntax"> </span><span class="identifier-syntax">table</span><span class="plain-syntax"> </span><span class="identifier-syntax">of</span><span class="plain-syntax"> </span><span class="identifier-syntax">S2</span>
</pre>
<p class="commentary">Again, this is null-terminated, which is safe since all symbol IDs are at least
<span class="extract"><span class="extract-syntax">SYMBOL_BASE_VAL</span></span>, a huge number.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the symbol wirings</span><span class="named-paragraph-number">10.1.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S1_table</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">S1_table_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S1_table</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"invalid symbols table in wiring"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">S1_symbol_ID</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">S1_symbol_ID</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S1_symbol_ID</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">S2_table_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">S2_table_ID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">S2_table_ID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">S2_symbol_ID</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S2_table</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">S2_table_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">S1_table</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"invalid symbols table in wiring"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S1</span><span class="plain-syntax"> = </span><a href="2-st.html#SP13" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_ID</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S1_table</span><span class="plain-syntax">, </span><span class="identifier-syntax">S1_symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S2</span><span class="plain-syntax"> = </span><a href="2-st.html#SP13" class="function-link"><span class="function-syntax">InterSymbolsTable::symbol_from_ID</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S2_table</span><span class="plain-syntax">, </span><span class="identifier-syntax">S2_symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">S1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">S2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">))</span>
<span class="plain-syntax">                </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"invalid symbols in wiring"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><a href="2-tw2.html#SP5" class="function-link"><span class="function-syntax">Wiring::wire_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S1</span><span class="plain-syntax">, </span><span class="identifier-syntax">S2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1">&#167;10.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_4" class="paragraph-anchor"></a><b>&#167;10.2.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the symbol wirings</span><span class="named-paragraph-number">10.2.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_OVER_RESOURCE_IDS</span><span class="plain-syntax">(</span><span class="identifier-syntax">ID</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_symbols_table</span><span class="plain-syntax"> *</span><span class="identifier-syntax">from_T</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP8" class="function-link"><span class="function-syntax">InterWarehouse::get_symbols_table</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">from_T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">table_needed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOOP_OVER_SYMBOLS_TABLE</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">from_T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::is_wired</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">table_needed</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                        </span><span class="identifier-syntax">table_needed</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">W</span><span class="plain-syntax"> = </span><a href="2-tw2.html#SP2" class="function-link"><span class="function-syntax">Wiring::wired_to</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">owning_table</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">W</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">symbol_ID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">table_needed</span><span class="plain-syntax">) </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2">&#167;10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_5" class="paragraph-anchor"></a><b>&#167;10.1.5. </b>Finally the bytecode block. Surprisingly, this is easy to handle here, but
only because a non-trivial part of the process is handled elsewhere.
</p>

<p class="commentary">Note that this loop continues until the file runs out.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the bytecode</span><span class="named-paragraph-number">10.1.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">X</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">X</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_package</span><span class="plain-syntax"> *</span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">extent</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">X</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_5_1" class="named-paragraph-link"><span class="named-paragraph">Read the preframe</span><span class="named-paragraph-number">10.1.5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><a href="2-in.html#SP2" class="function-link"><span class="function-syntax">Inode::new_node</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="identifier-syntax">extent</span><span class="plain-syntax">-1, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">owner</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_5_2" class="named-paragraph-link"><span class="named-paragraph">Read the frame</span><span class="named-paragraph-number">10.1.5.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP10_1_5_3" class="named-paragraph-link"><span class="named-paragraph">Correct and verify the frame</span><span class="named-paragraph-number">10.1.5.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><a href="2-np.html#SP3" class="function-link"><span class="function-syntax">NodePlacement::move_to_moving_bookmark</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">at</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1">&#167;10.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_2_5" class="paragraph-anchor"></a><b>&#167;10.2.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the bytecode</span><span class="named-paragraph-number">10.2.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="2-it.html#SP7" class="function-link"><span class="function-syntax">InterTree::traverse_root_only</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><a href="3-iibf.html#SP11" class="function-link"><span class="function-syntax">BinaryInter::frame_writer</span></a><span class="plain-syntax">, </span><span class="identifier-syntax">fh</span><span class="plain-syntax">, -</span><span class="constant-syntax">PACKAGE_IST</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-it.html#SP8" class="function-link"><span class="function-syntax">InterTree::traverse</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><a href="3-iibf.html#SP11" class="function-link"><span class="function-syntax">BinaryInter::frame_writer</span></a><span class="plain-syntax">, </span><span class="identifier-syntax">fh</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_2">&#167;10.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::frame_writer</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::frame_writer</span></span>:<br/><a href="3-iibf.html#SP10_2_5">&#167;10.2.5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_tree</span><span class="plain-syntax"> *</span><span class="identifier-syntax">I</span><span class="plain-syntax">, </span><span class="reserved-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">state</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fh</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">FILE</span><span class="plain-syntax"> *) </span><span class="identifier-syntax">state</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP11_1" class="named-paragraph-link"><span class="named-paragraph">Write the preframe</span><span class="named-paragraph-number">11.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="3-iibf.html#SP11_2" class="named-paragraph-link"><span class="named-paragraph">Write the frame</span><span class="named-paragraph-number">11.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10_1_5_1" class="paragraph-anchor"></a><b>&#167;10.1.5.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the preframe</span><span class="named-paragraph-number">10.1.5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">.</span><span class="element-syntax">error_offset</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">size_t</span><span class="plain-syntax">) </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">) - </span><span class="constant-syntax">PREFRAME_SIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">extent</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">2</span><span class="plain-syntax">) || ((</span><span class="reserved-syntax">long</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">extent</span><span class="plain-syntax"> &gt;= </span><span class="identifier-syntax">max_offset</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP12" class="function-link"><span class="function-syntax">BinaryInter::read_error</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="identifier-syntax">ftell</span><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"wildly overlarge instruction frame"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">PID</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="3-iibf.html#SP5" class="function-link"><span class="function-syntax">BinaryInter::read_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">PID</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">PID</span><span class="plain-syntax"> = </span><span class="identifier-syntax">grid</span><span class="plain-syntax">[</span><span class="identifier-syntax">PID</span><span class="plain-syntax">];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">PID</span><span class="plain-syntax">) </span><span class="identifier-syntax">owner</span><span class="plain-syntax"> = </span><a href="2-tw.html#SP9" class="function-link"><span class="function-syntax">InterWarehouse::get_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">warehouse</span><span class="plain-syntax">, </span><span class="identifier-syntax">PID</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_5">&#167;10.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_1" class="paragraph-anchor"></a><b>&#167;11.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the preframe</span><span class="named-paragraph-number">11.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax"> + </span><span class="constant-syntax">1</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><a href="2-in.html#SP6" class="function-link"><span class="function-syntax">Inode::get_package</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">resource_ID</span><span class="plain-syntax">));</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP11">&#167;11</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_5_2" class="paragraph-anchor"></a><b>&#167;10.1.5.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Read the frame</span><span class="named-paragraph-number">10.1.5.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">extent</span><span class="plain-syntax">-1; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">word</span><span class="plain-syntax"> = </span><a href="3-iibf.html#SP6" class="function-link"><span class="function-syntax">BinaryInter::read_next</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">] = </span><span class="identifier-syntax">word</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_5">&#167;10.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP11_2" class="paragraph-anchor"></a><b>&#167;11.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Write the frame</span><span class="named-paragraph-number">11.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="function-syntax">&lt;P-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">extent</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><a href="3-iibf.html#SP7" class="function-link"><span class="function-syntax">BinaryInter::write_word</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">fh</span><span class="plain-syntax">, (</span><span class="reserved-syntax">unsigned</span><span class="plain-syntax"> </span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">P</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">W</span><span class="plain-syntax">.</span><span class="element-syntax">instruction</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">]));</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP11">&#167;11</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP10_1_5_3" class="paragraph-anchor"></a><b>&#167;10.1.5.3. </b>That just leaves the process of correction. We do two things:
</p>

<ul class="items"><li>(a) Transposition: this means correcting all references to warehouse IDs in the
old tree into references to those in the new, by performing <span class="extract"><span class="extract-syntax">id = grid[id]</span></span>.
We cannot do this without knowing which words in the bytecode are warehouse IDs,
though, so we must call a method of the construct for the instruction.
</li><li>(b) Verification: also construct-specific, also done via a method call, this not
only performs sanity checks on the bytecode for the instruction but also
completes the process of embedding the instruction by, for example, setting
the definition of any symbol created in the instruction to <span class="extract"><span class="extract-syntax">P</span></span>.
</li></ul>
<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Correct and verify the frame</span><span class="named-paragraph-number">10.1.5.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">inter_error_message</span><span class="plain-syntax"> *</span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">grid</span><span class="plain-syntax">) </span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-ic.html#SP22" class="function-link"><span class="function-syntax">InterInstruction::transpose_construct</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">grid</span><span class="plain-syntax">, </span><span class="identifier-syntax">grid_extent</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">E</span><span class="plain-syntax">) { </span><a href="3-ie.html#SP5" class="function-link"><span class="function-syntax">InterErrors::issue</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">); </span><span class="identifier-syntax">exit</span><span class="plain-syntax">(1); }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">E</span><span class="plain-syntax"> = </span><a href="3-vi.html#SP1" class="function-link"><span class="function-syntax">VerifyingInter::instruction</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">owner</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">E</span><span class="plain-syntax">) { </span><a href="3-ie.html#SP5" class="function-link"><span class="function-syntax">InterErrors::issue</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">E</span><span class="plain-syntax">); </span><span class="identifier-syntax">exit</span><span class="plain-syntax">(1); }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="3-iibf.html#SP10_1_5">&#167;10.1.5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>Errors in reading binary inter are not recoverable:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">BinaryInter::read_error</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">BinaryInter::read_error</span></span>:<br/><a href="3-iibf.html#SP6">&#167;6</a>, <a href="3-iibf.html#SP10_1_1">&#167;10.1.1</a>, <a href="3-iibf.html#SP10_1_2">&#167;10.1.2</a>, <a href="3-iibf.html#SP10_1_3_1">&#167;10.1.3.1</a>, <a href="3-iibf.html#SP10_1_3_2">&#167;10.1.3.2</a>, <a href="3-iibf.html#SP10_1_3_2_2_1">&#167;10.1.3.2.2.1</a>, <a href="3-iibf.html#SP10_1_4">&#167;10.1.4</a>, <a href="3-iibf.html#SP10_1_5_1">&#167;10.1.5.1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">inter_error_location</span><span class="plain-syntax"> *</span><span class="identifier-syntax">eloc</span><span class="plain-syntax">, </span><span class="reserved-syntax">long</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">err</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">error_offset</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">size_t</span><span class="plain-syntax">) </span><span class="identifier-syntax">at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="3-ie.html#SP5" class="function-link"><span class="function-syntax">InterErrors::issue</span></a><span class="plain-syntax">(</span><a href="3-ie.html#SP4" class="function-link"><span class="function-syntax">InterErrors::plain</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">err</span><span class="plain-syntax">, </span><span class="identifier-syntax">eloc</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">exit</span><span class="plain-syntax">(1);</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="3-ic.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-bm.html">1</a></li><li class="progresschapter"><a href="2-it.html">2</a></li><li class="progresscurrentchapter">3</li><li class="progresssection"><a href="3-ic.html">ic</a></li><li class="progresscurrent">iibf</li><li class="progresssection"><a href="3-iitf.html">iitf</a></li><li class="progresssection"><a href="3-vi.html">vi</a></li><li class="progresssection"><a href="3-ivp.html">ivp</a></li><li class="progresssection"><a href="3-idt.html">idt</a></li><li class="progresssection"><a href="3-mtd.html">mtd</a></li><li class="progresssection"><a href="3-ie.html">ie</a></li><li class="progresssection"><a href="3-tp.html">tp</a></li><li class="progresschapter"><a href="4-tcc.html">4</a></li><li class="progresschapter"><a href="5-tac.html">5</a></li><li class="progresschapter"><a href="6-tpc.html">6</a></li><li class="progressnext"><a href="3-iitf.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

